#ifndef GLOBAL_H_
#define GLOBAL_H_

#include <semaphore.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
///global variable
#define SMARTHOME_DEBUG			///Debug Mode

#define PORT 1234				///port
#define SHARENAME "/data/local/myshm" 	///the name of shared memory.can change!
#define SHARESIZE 4096 			///the size of shared memory.
#define WAITRES	600				///wait 600*myDelay(5) ms, if no response, return "#ff ff ff ffff#ff#ff ff#ff#"
#define WAITNUM	1000			///wait 1000*myDelay(5) ms, the command will go on
///some global functions
#ifdef SMARTHOME_DEBUG
#include<android/log.h>
#define TAGTEST "guodian"
#define LOGI(FORM,INFO) __android_log_print(ANDROID_LOG_DEBUG,TAGTEST,FORM,INFO)

	#define ERROROUT(ERRSTR) \
			{printf(ERRSTR);\
			if(errno!=0) printf("---%s",strerror(errno));\
			printf("\t file name:%s",__FILE__);\
			LOGI("\t file name:%s",__FILE__);  \
			printf("\t file current line:%d\n",__LINE__);}
	#define PRINTOUT(FORMAT,INFO) \
			{printf(FORMAT,INFO);printf("\n");LOGI(FORMAT,INFO);}
#endif

enum{shm_CLEAR,shm_WRITEDNO,shm_WRITED,shm_SWRITED,shm_RESULT,shm_DISPOSE,shm_ALARM,shm_DEVLIST,shm_TIME,shm_CMD,shm_BEALARM,shm_UPGRADE,shm_UPRESPOND,shm_STATUS};
#define setFlagNo() (g_addr[0]=shm_WRITEDNO)
#define setFlag() (g_addr[0]=shm_WRITED)
#define dispose() (g_addr[0]=shm_DISPOSE)
#define clearFlag() (g_addr[0]=shm_CLEAR)
#define isSet() (g_addr[0]==shm_WRITED || g_addr[0]==shm_WRITEDNO || g_addr[0]==shm_SWRITED)
#define haveRES() (g_addr[0]==shm_WRITED || g_addr[0]==shm_WRITEDNO)
#define isClear() (g_addr[0]==shm_CLEAR)
#define isResult() (g_addr[0]==shm_RESULT)
#define setCMDFlag() (g_addr[0]=shm_CMD)
#define isCMDFlag() (g_addr[0]==shm_CMD)

void myDelay(int);

#endif
